#include <stdio.h>

struct complex_num
{
    float real;
    float complex;
};

void input_complex_num(struct complex_num* num);
void print_complex_num(struct complex_num* num);
void complex_sum(struct complex_num* c1, struct complex_num* c2, struct complex_num* re);
void complex_difference(struct complex_num* c1, struct complex_num* c2, struct complex_num* re);
void complex_product(struct complex_num* c1, struct complex_num* c2, struct complex_num* re);
void complex_quotient(struct complex_num* c1, struct complex_num* c2, struct complex_num* re);

int main()
{
    struct complex_num c1, c2, re;
    input_complex_num(&c1);
    input_complex_num(&c2);
    printf("sum:");
    complex_sum(&c1, &c2, &re);
    print_complex_num(&re);
    printf("difference:");
    complex_difference(&c1, &c2, &re);
    print_complex_num(&re);
    printf("product:");
    complex_product(&c1, &c2, &re);
    print_complex_num(&re);
    printf("quotient:");
    complex_quotient(&c1, &c2, &re);
    print_complex_num(&re);
    return 0;
}

void input_complex_num(struct complex_num* num)
{
    scanf("%f+%fi", &num->real, &num->complex);
}

void print_complex_num(struct complex_num* num)
{
    printf("%f+%fi\n", num->real, num->complex);
}

void complex_sum(struct complex_num* c1, struct complex_num* c2, struct complex_num* re)
{
    re->real = c1->real + c2->real;
    re->complex = c1->complex + c2->complex;
}

void complex_difference(struct complex_num* c1, struct complex_num* c2, struct complex_num* re)
{
    re->real = c1->real - c2->real;
    re->complex = c1->complex - c2->complex;
}

void complex_product(struct complex_num* c1, struct complex_num* c2, struct complex_num* re)
{
    re->real = c1->real * c2->real - c1->complex * c2->complex;
    re->complex = c1->real * c2->complex + c1->complex * c2->real;
}

void complex_quotient(struct complex_num* c1, struct complex_num* c2, struct complex_num* re)
{
    if(c1->complex == 0 && c2->complex == 0)
    {
        re->real = c1->real / c2->real;
        re->complex = 0;
        return;
    }
    int num = c1->complex * c1->complex + c2->complex*c2->complex;
    re->real = c1->real * c2->real + c1->complex * c2->complex;
    re->complex = c1->complex * c2->real - c1->real * c2->complex;
}
